use super::*;

pub struct Lock {
    key: Box<dyn ICondition>,
    child: Box<dyn ITask>,
}

impl Lock {
    pub fn new(key: Box<dyn ICondition>, child: Box<dyn ITask>) -> Box<Self> {
        Box::new(Self {
            key,
            child,
        })
    }
}

impl ITask for Lock {
    fn step(&mut self) {
        if self.key.check() {
           self.child.step(); 
        }
    }

    fn reset(&mut self) {
        self.key.reset();
        self.child.reset();
    }

    fn is_finished(&self) -> bool {
        self.child.is_finished() 
    }
}

